package com.hec.yygh.oss.service.impl;

import com.hec.yygh.oss.service.FileService;

import com.hec.yygh.oss.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private QiniuUtils qiniuUtils;

    @Value("${qiniu.oss.file.path}")
    private String bucketName;


    @Override
    public String upload(MultipartFile file) {
        String filename = file.getOriginalFilename();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        filename=uuid + filename;
        //上传文件
        boolean upload = qiniuUtils.upload(file,filename);
        if (upload){
            String url = "http://"+bucketName+"/"+filename;
            return url;
        }else{
            return null;
        }
    }
}
